﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProDivingAdmin2salmon14
{
    public partial class DiverForm : Form, IDiverForm
    {
        public DiverForm()
        {
            InitializeComponent();
            //this.dataGridViewDiverList.Columns.Remove("isInjured");
            //this.dataGridViewDiverList.Columns.Remove("isDisqualified");

            this.VisibleChanged += new EventHandler(GetList);

        }

        private void GetList(object sender, EventArgs e) 
        {
            if (EventGetListOfDivers != null)
            {
                this.dataGridViewDiverList.DataSource = EventGetListOfDivers();
                this.dataGridViewDiverList.Columns["isInjured"].ReadOnly = true;
                this.dataGridViewDiverList.Columns["isDisqualified"].ReadOnly = true;

                this.dataGridViewDiverList.Columns["nationality"].HeaderText = "Nationality";

                this.dataGridViewDiverList.Columns["fullName"].HeaderText = "Name";
                this.dataGridViewDiverList.Columns["fullName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }
        }

        public event DelegateGetListOfDivers EventGetListOfDivers = null;
        public event DelegateDisqualifyDiver EventDisqualifyDiver = null;
        public event DelegateMarkDiverAsInjured EventMarkDiverAsInjured = null;

        private void DiverForm_FormClosed(object sender, FormClosedEventArgs e)
        {
        }

        private void buttonInjure_Click(object sender, EventArgs e)
        {
            Diver tempDiver = (Diver)this.dataGridViewDiverList.CurrentRow.DataBoundItem;

            System.Windows.Forms.DialogResult result = MessageBox.Show("Are you sure?", "Really?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                if (EventMarkDiverAsInjured != null)
                {
                    EventMarkDiverAsInjured(tempDiver);
                }
                this.dataGridViewDiverList.Invalidate();
            }
        }

        private void buttonDisqualify_Click(object sender, EventArgs e)
        {
            Diver tempDiver = (Diver)this.dataGridViewDiverList.CurrentRow.DataBoundItem;

            System.Windows.Forms.DialogResult result = MessageBox.Show("Are you sure?", "Really?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                if (EventDisqualifyDiver != null)
                {
                    EventDisqualifyDiver(tempDiver);
                }
                this.dataGridViewDiverList.Invalidate();
            }
        }
    }
}
